//
//  AppDelegate.m
//  Movie
//
//  Created by lanou3g on 15/6/30.
//  Copyright (c) 2015年 四黑. All rights reserved.
//

#import "AppDelegate.h"
#import "MovieViewController.h"
#import "CinemaViewController.h"
#import "DiscoveryViewController.h"
#import "MyViewController.h"

#import "MainBaseViewController.h"


@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc{
    
    _window = nil;
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]]autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self createUITabBarController];//创建UITabBarController
  
    [self.window makeKeyAndVisible];
    // Override point for customization after application launch.
    return YES;
}


#pragma mark *** 创建UITabBarController
- (void)createUITabBarController{
    
    
    MovieViewController *movieVC = [[MovieViewController alloc]init];
    CinemaViewController *cinemaVC = [[CinemaViewController alloc]init];
    DiscoveryViewController *discoverVC = [[DiscoveryViewController alloc]init];
    MyViewController *myVC = [[MyViewController alloc]init];
    MyViewController *testVC = [[MyViewController alloc]init];
    
    UINavigationController *movieNavigation = [[UINavigationController alloc]initWithRootViewController:movieVC];
    UINavigationController *cinemaNavigation = [[UINavigationController alloc]initWithRootViewController:cinemaVC];
    UINavigationController *discoverNavigation = [[UINavigationController alloc]initWithRootViewController:discoverVC];
  
    //设置标题
    movieNavigation.tabBarItem.title = @"电影";
    cinemaNavigation.tabBarItem.title = @"影院";
    discoverNavigation.tabBarItem.title = @"发现";
    myVC.tabBarItem.title = @"我的";
    testVC.tabBarItem.title = @"她的";
    
    //设置图片
    movieNavigation.tabBarItem.image = [UIImage imageNamed:@"iconfont-dianying"];
    cinemaNavigation.tabBarItem.image = [UIImage imageNamed:@"iconfont-yingyuana"];
    discoverNavigation.tabBarItem.image = [UIImage imageNamed:@"iconfont-faxian"];
    myVC.tabBarItem.image = [UIImage imageNamed:@"iconfont-wode"];
    testVC.tabBarItem.image = [UIImage imageNamed:@"iconfont-yingyuana"];
    UITabBarController *tabBarVC = [[UITabBarController alloc]init];
    tabBarVC.viewControllers = @[movieNavigation,cinemaNavigation,discoverNavigation,myVC,testVC];
//    tabBarVC.selectedViewController = movieNavigation;//进入是默认界面
    tabBarVC.delegate =self;
    tabBarVC.tabBar.tintColor = [UIColor redColor];//被选中之后tabl 的颜色
    
    self.window.rootViewController = tabBarVC;
    
    [movieVC release];
    [cinemaVC release];
    [discoverVC release];
    [myVC release];

    [movieNavigation release];
    [cinemaNavigation release];
    [discoverNavigation release];
    
    [tabBarVC release];
    
}

#pragma mark *** UITabBarController代理方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
    NSLog(@"viewConteoller:%@",viewController);
    NSLog(@"index:%ld",tabBarController.selectedIndex);
    
}




- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
